package io.github.wppli.domain.pay.event;

import io.github.wppli.domain.pay.model.entity.ProductEntity;
import io.github.wppli.domain.recommond.model.entity.UserBehaviorEntity;
import io.github.wppli.types.event.BaseEvent;
import io.github.wppli.types.snow.SnowflakeIdGenerator;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author li--jiaqiang 2025−03−22
 */
@Component
public class OrderBehaviorsEvent extends BaseEvent<OrderBehaviorsEvent.OrderBehaviorsEntity>  {

    @Value("${spring.rabbitmq.topic.orderBehaviors}")
    private String topic;

    @Resource
    private SnowflakeIdGenerator snowflakeIdGenerator;

    @Override
    public EventMessage<OrderBehaviorsEntity> buildEventMessage(OrderBehaviorsEntity data) {
        return EventMessage.<OrderBehaviorsEvent.OrderBehaviorsEntity>builder()
                .id(String.valueOf(snowflakeIdGenerator.nextId()))
                .timestamp(new Date())
                .data(data)
                .build();
    }

    @Override
    public String topic() {
        return topic;
    }

    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    public static class OrderBehaviorsEntity {
        private ProductEntity productEntity;
        private UserBehaviorEntity userBehaviorEntity;

    }
}